package my.jwds.p917;

public class ReverseOnlyLetters {

    public static void main(String[] args) {
        ReverseOnlyLetters obj = new ReverseOnlyLetters();
        System.out.println(obj.reverseOnlyLetters(""));
    }

    public String reverseOnlyLetters(String s) {
        int start = 0;
        int end = s.length() -1;
        char[] chars = s.toCharArray();
        while(start < end){
            if (!isLetter(chars[start])){
                start ++;
            }else if (!isLetter(chars[end])){
                end--;
            }else{
                char temp = chars[start];
                chars[start++] = chars[end];
                chars[end--] = temp;
            }
        }
        return new String(chars);
    }

    private boolean isLetter(char c){
        return c >= 'a' && c <= 'z' || c >='A' && c<='Z';
    }
}